<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRiskSourcesTable extends Migration
{
    public function up()
    {
        Schema::create('risk_sources', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->bigInteger('employees_id')->nullable()->comment('员工ID');
            $table->string('location')->comment('风险源位置');
            $table->string('risk_level')->comment('风险类型[低风险, 一般风险, 较大风险, 重大风险]');
            $table->text('description')->comment('风险描述');
            $table->string('pose_risk')->comment('造成风险');
            $table->json('accident_type')->nullable()->comment('事故类型');
            $table->string('status')->default('pending')->comment('状态[pending:待处理,processing:处理中,rectification:暂时处理,resolved:已处理]');
            $table->text('control_measure')->comment('控制措施');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('修改时间');
            $table->timestamp('deleted_at')->nullable()->comment('删除时间');
        });

        DB::statement('alter table'. ' ' .config('database.connections.mysql.prefix', '').'risk_sources comment "风险源表"');

    }

    public function down()
    {
        Schema::dropIfExists('risk_sources');     // 风险源表
    }
}
